/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  							 script_conditional_action.cpp

	$Header: /heroes4/script_conditional_action.cpp $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"
#include "script_conditional_action.h"

// --------------------------------------------------------------------------
// t_script_conditional_action members
// --------------------------------------------------------------------------

// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_script_conditional_action::read_from_map(
	std::streambuf &	stream,
	int					format_version )
{
	m_condition_ptr = t_condition::reconstruct_from_map( stream, format_version );
	if ( m_condition_ptr.get() == 0 )
		return false;

	return t_script_branch_action::read_from_map( stream, format_version );
}

bool t_script_conditional_action::read( std::streambuf& stream, int version )
{
	if (!t_script_branch_action::read( stream, version ))
		return false;

	m_condition_ptr = t_condition::reconstruct( stream, version );
	
	return (m_condition_ptr.get() != NULL );
}

bool t_script_conditional_action::write( std::streambuf& stream ) const
{
	if (!t_script_branch_action::write( stream ))
		return false;
	
	return m_condition_ptr->write( stream );
}


void t_script_conditional_action::execute(t_script_context_hero const& context ) const
{
	if (get_condition().evaluate(context))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

void t_script_conditional_action::execute(t_script_context_town const& context ) const
{
	if (get_condition().evaluate(context))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

void t_script_conditional_action::execute(t_script_context_object const& context ) const
{
	if (get_condition().evaluate(context))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

void t_script_conditional_action::execute(t_script_context_army const& context ) const
{
	if (get_condition().evaluate(context))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

void t_script_conditional_action::execute(t_script_context_global const& context ) const
{
	if (get_condition().evaluate(context))
		get_true_subaction().execute(context);
	else
		get_false_subaction().execute(context);
}

